import org.grails.plugins.lookups.Lookup
import org.grails.plugins.lookups.LookupValue
class BootStrap {

     def init = { servletContext ->    
     
        def studentLevel = Lookup.findByRealm('studentLevel') 
        studentLevel = studentLevel?studentLevel:new Lookup(realm:"studentLevel",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"", 
                                        valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save();

      
        ['无','大队长', '中队长','班长','学习委员'].eachWithIndex{it, index ->
         new LookupValue(lookup: studentLevel ,
                                        code: it,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }

         // 教师学历
        def teacherdegree = Lookup.findByRealm('teacherdegree') 
        teacherdegree = teacherdegree?teacherdegree : new Lookup(realm:"teacherdegree",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"",
                                         valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save();
      
        ['高中', '专科','本科','研究生','硕士','博士'].eachWithIndex{it, index ->
         new LookupValue(lookup:teacherdegree ,
                                        code: it,
                                        value: it, 
                                        sequencer: index,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }

       
         // 教师职称
        def ts = Lookup.findByRealm('teacherstaff') 
        ts = ts?ts:new Lookup(realm:"teacherstaff",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"",
                                         valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save();

       
         ['无职称', '初级职称','中级职称','高级职称'].eachWithIndex{it, index ->
         new LookupValue(lookup: ts ,
                                        code: it,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }

 

         // 教师政治面貌
         def tf = Lookup.findByRealm('teacherfeatures') 
        tf = tf?tf:new Lookup(realm:"teacherfeatures",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"",
                                         valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save();

         ['无', '团员','党员'].eachWithIndex{it, index ->
         new LookupValue(lookup: tf ,
                                        code: it,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }
 

         // 系统中有的学科
         def courses = Lookup.findByRealm('courses') 
        courses = courses?courses:new Lookup(realm:"courses",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"",
                                         valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date() ).save();

         ['语文', '数学','化学', '物理','地理', '历史','英语', '生物','音乐','体育'].eachWithIndex{it, index ->
         new LookupValue(lookup: courses ,
                                        code: it,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }
  
         // 学校年级
         def grades = Lookup.findByRealm('grades') 
        grades = grades?grades:new Lookup(realm:"grades",
                                        codeType:"integer",
                                        codeMinimum:"",
                                        codeMaximum:"",
                                        valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date() ).save();
     
         ['新生', '一年级', '二年级','三年级', '四年级','五年级', '六年级','毕业'].eachWithIndex{it, index ->
         new LookupValue(lookup: grades ,
                                        code: index,
                                        value: it, 
                                        sequencer : index,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }
  

         // 学校年级的班
         def teams = Lookup.findByRealm('teams') 
        teams = teams?teams:new Lookup(realm:"teams",
                                        codeType:"integer",
                                        codeMinimum:"",
                                        codeMaximum:"",
                                         valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date() ).save();

         ['一班', '二班', '三班','四班', '五班','六班', '实验班','体育班'].eachWithIndex{it, index ->
         new LookupValue(lookup: teams ,
                                        code: index,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }

        ['ROLE_TEACHER':'代课老师',
        'ROLE_MASTER_TEACHER':'班主任', 
        'ROLE_LEADER_TEACHER':'教学主任',
        'ROLE_SCHOOL_MASTER':'校长',
        'ROLE_ADMIN':'系统管理员'].each{ entry ->
         new Role(authority:entry.key,
                        description:entry.value).save()
        }

                 // 老师的个人文档栏目
         def personalCategory = Lookup.findByRealm('personalCategory') 
        personalCategory = personalCategory?personalCategory:new Lookup(realm:"personalCategory",
                                        codeType:"string",
                                        codeMinimum:"",
                                        codeMaximum:"",
                                        valueType:"string",
                                        valueMinimum:"",
                                        valueMaximum:"",
                                        valueScale:"",
                                        ordering:"sequencer",
                                        internationalize:false,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date() ).save();

         ['我的文档' , '教学计划','教案课件','科研论文'].eachWithIndex{it, index ->
         new LookupValue(lookup: personalCategory ,
                                        code: it,
                                        value: it, 
                                        sequencer : index ,
                                        stringSequencer: it,
                                        dateCreated:new Date(),
                                        lastUpdated:new Date()).save()
        }
         
     
     }
     def destroy = { 
     }
} 